package com.food.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.food.dao.service.RecipeService;
import com.food.model.Recipe;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=utf-8");
		
		RecipeService recipeService = new RecipeService(); 	
		List<Recipe> listRecipe = recipeService.findTenNewRecipe();
		List<Recipe> listRecipeScore = recipeService.findTopTenScore();
		
		
		
		request.setAttribute("listRecipe", listRecipe);
		request.setAttribute("listRecipeScore", listRecipeScore);
		
		RequestDispatcher rd = request
				.getRequestDispatcher("/index_true.jsp");
		rd.forward(request, response);
		return;
	}

}
